package com.tr.rentcar.controller.loginandregister;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.codec.digest.DigestUtils;

import com.tr.rentcar.model.dao.UserDao;

/**
 * Servlet implementation class FindController
 */
@WebServlet("/findpassword")
public class FindPasswordController extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
  
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.getRequestDispatcher("WEB-INF/jsp/find.jsp").forward(request, response);
	}
	
	/**
	 * 找回密码后修改密码
	 */
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		try {
			String tel=req.getParameter("tel");
			String password=DigestUtils.md5Hex(req.getParameter("password"));
			boolean status=new UserDao().updatePassword(tel, password);
			resp.getWriter().println(status);     
	        resp.flushBuffer(); 
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
